package com.csd.action.team;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csd.helper.ActionResult;
import com.csd.helper.Tool;
import com.csd.pojo.Student;
import com.csd.pojo.Team;
import com.csd.serviceImpl.TeamService;
//new add
import com.csd.serviceImpl.ProjectTypeService;
import com.csd.dao.TeamDAO;
import com.csd.serviceImpl.StudentService;
import com.csd.pojo.Project;
import com.csd.pojo.ProjectType;

/**
 * 
 * 查看团队信息
 * @author csd
 * @version 1.0
 * 
 * <br> 修订时间：2009-12-17
 * <br> 修改原因：创建文件
 * <br> 修改人：刘世彬
 * 
 * <br> 
 * 
 */
public class TeamShowAction {
	
	private Team team ;

	private List<Student> members;

	private String next;
	private Integer  projectTypeID;
	private Integer teamID;
	private TeamService service;
	private Student member;//new add
	private ProjectTypeService projectTypeService;
	private StudentService studentService;//new add
	
	
	public Student getMember() {
		return member;
	}

	public void setMember(Student member) {
		this.member = member;
	}
    
	public StudentService getStudentService() {
		return studentService;
	}

	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	
	public ProjectTypeService getProjectTypeService() {
		return projectTypeService;
	}

	public void setProjectTypeService(ProjectTypeService projectTypeService) {
		this.projectTypeService = projectTypeService;
	}

	public Integer getTeamID() {
		return teamID;
	}

	public void setTeamID(Integer teamID) {
		this.teamID = teamID;
	}

	public String getNext() {
		return next;
	}

	public void setNext(String next) {
		this.next = next;
	}

	public List<Student> getMembers() {
		return members;
	}

	public void setMembers(List<Student> members) {
		this.members = members;
	}


	public TeamService getService() {
		return service;
	}

	public void setService(TeamService service) {
		this.service = service;
	}
	
	public Team getTeam() {
		return team;
	}

	public void setTeam(Team team) {
		this.team = team;
	}

	public Integer  getProjectTypeID() {
		return projectTypeID;
	}

	public void setProjectTypeID(Integer  projectTypeID) {
		this.projectTypeID = projectTypeID;
	}
	
	@SuppressWarnings("unchecked")
	public String execute()
	{
		String result = ActionResult.fail;
		HttpSession session = ServletActionContext.getRequest().getSession();
	    int r = projectTypeService.getProjectTypeMaxMemberByID(this.projectTypeID);//获取项目类型人数上限并提交给myTeam.jsp页面
	    session.setAttribute("projectMaxMemberCount", r);
		// 从session中取ID，根据ID查询数据 
		this.team = service.getTeam();
		
		// 存储团队是否已经申请项目的状态
		boolean flag = false;
			
		if(this.team != null)
		{
			this.members = Tool.setToList(this.team.getMembers());
			this.teamID = this.team.getId();
			flag = service.hasProjectOrNot(this.team.getId());
			result = ActionResult.success;
		}
		
		// 判断跳转链接是否存在projectTypeID属性
		try {
			int type = this.projectTypeID;
			if (type > 0)
				flag = true;
			
		} catch (Exception e) {
			;
		}
		session.setAttribute("hasProjectOrNot", flag);
		return result;
	}
}
